package com.engine4cloud.tdf.supervision.controller.inner;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.common.security.annotation.Inner;
import com.engine4cloud.tdf.supervision.dto.create.DcpgSurveyCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.DcpgEvaluateQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.DcpgSurveyResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.DcpgSurveyUpdateDTO;
import com.engine4cloud.tdf.supervision.service.DcpgSurveyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

/**
 * 调查评估-调查-inner
 *
 * @author wenjie
 * @date 2024-07-29 11:07:43
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/inner/survey")
@Tag(description = "SurveyWeb", name = "调查评估-调查-inner")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class DcpgSurveyInnerController {

    private final DcpgSurveyService dcpgSurveyService;

    /**
     * 分页查询
     *
     * @param dto  调查评估-调查
     * @return R<PageInfo < DcpgSurveyResultDTO>>
     */
    @Inner
    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/page")
    public R<PageInfo<DcpgSurveyResultDTO>> getSurveyPage(@Valid @RequestBody DcpgEvaluateQueryDTO dto) {
        return R.ok(dcpgSurveyService.pageList(dto));
    }


    /**
     * 通过id查询调查评估-调查
     *
     * @param id id
     * @return R
     */
    @Inner
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<DcpgSurveyResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(dcpgSurveyService.getById(id));
    }

    /**
     * 新增调查评估-调查
     *
     * @param dto 调查评估-调查
     * @return R
     */
    @Inner
    @Operation(summary = "新增调查评估-调查", description = "新增调查评估-调查")
    @SysLog("新增调查评估-调查")
    @PostMapping
    public R<Boolean> create(@Valid @RequestBody DcpgSurveyCreateDTO dto) {
        return R.ok(dcpgSurveyService.create(dto));
    }

    /**
     * 修改调查评估-调查
     *
     * @param dto 调查评估-调查
     * @return R
     */
    @Inner
    @Operation(summary = "修改调查评估-调查", description = "修改调查评估-调查")
    @SysLog("修改调查评估-调查")
    @PutMapping
    public R<Boolean> update(@Valid @RequestBody DcpgSurveyUpdateDTO dto) {
        return R.ok(dcpgSurveyService.update(dto));
    }

    /**
     * 通过id删除调查评估-调查
     *
     * @param ids id列表
     * @return R
     */
    @Inner
    @Operation(summary = "通过id删除调查评估-调查", description = "通过id删除调查评估-调查")
    @SysLog("通过id删除调查评估-调查")
    @DeleteMapping
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(dcpgSurveyService.removeBatchByIds(CollUtil.toList(ids)));
    }
}